package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"go.uber.org/zap"
	"time"
)

// @Tags UserProjectRefund
// @Summary 创建UserProjectRefund
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserProjectRefund true "创建UserProjectRefund"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userProjectRefund/createUserProjectRefund [post]
func CreateUserProjectRefund(c *gin.Context) {
	var userProjectRefund model.UserProjectRefund
	_= c.ShouldBindJSON(&userProjectRefund)

	if err := service.CreateUserProjectRefund(userProjectRefund); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags UserProjectRefund
// @Summary 删除UserProjectRefund
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserProjectRefund true "删除UserProjectRefund"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /userProjectRefund/deleteUserProjectRefund [delete]
func DeleteUserProjectRefund(c *gin.Context) {
	var userProjectRefund model.UserProjectRefund
	_ = c.ShouldBindJSON(&userProjectRefund)
	if err := service.DeleteUserProjectRefund(userProjectRefund); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags UserProjectRefund
// @Summary 批量删除UserProjectRefund
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除UserProjectRefund"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /userProjectRefund/deleteUserProjectRefundByIds [delete]
func DeleteUserProjectRefundByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteUserProjectRefundByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags UserProjectRefund
// @Summary 更新UserProjectRefund
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserProjectRefund true "更新UserProjectRefund"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /userProjectRefund/updateUserProjectRefund [put]
type DateNullStruct struct {
	PayDate time.Time `json:"payDate"`
}
func UpdateUserProjectRefund(c *gin.Context) {
	Paydate := DateNullStruct{}
	var userProjectRefund model.UserProjectRefund
	_ = c.ShouldBindBodyWith(&userProjectRefund,binding.JSON)

	_ = c.ShouldBindBodyWith(&Paydate,binding.JSON)
	if Paydate.PayDate.Unix() >0 {
		userProjectRefund.PayDate.Time = Paydate.PayDate
		userProjectRefund.PayDate.Valid = true
	}
	if err := service.UpdateUserProjectRefund(userProjectRefund); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags UserProjectRefund
// @Summary 用id查询UserProjectRefund
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserProjectRefund true "用id查询UserProjectRefund"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /userProjectRefund/findUserProjectRefund [get]
func FindUserProjectRefund(c *gin.Context) {
	var userProjectRefund model.UserProjectRefund
	_ = c.ShouldBindQuery(&userProjectRefund)
	if err, reuserProjectRefund := service.GetUserProjectRefund(userProjectRefund.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reuserProjectRefund": reuserProjectRefund}, c)
	}
}

// @Tags UserProjectRefund
// @Summary 分页获取UserProjectRefund列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.UserProjectRefundSearch true "分页获取UserProjectRefund列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userProjectRefund/getUserProjectRefundList [get]
func GetUserProjectRefundList(c *gin.Context) {
	var pageInfo request.UserProjectRefundSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetNeal(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}


func GetRefundNealList(c *gin.Context){
	var pageInfo request.UserProjectRefundSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetNeal(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}